<?php
include_once 'fun.php';
include_once 'islogin.php';
$_SESSION['isadmin']=isset($_SESSION['isadmin'])?$_SESSION['isadmin']:'';
    if ($_SESSION['isadmin']!=4&&$_SESSION['isadmin']!=-1) {
        header('Refresh:1;url=shop.php');
        die("请以管理员身份登录");
    }
    //var_dump($_FILES);
    $Name = trim($_POST['Name']);
    $gender = ($_POST['gender']!='')?$_POST['gender']:'';
    $age =($_POST['age']!='')?(int)($_POST['age']):'';
    $admin = (int)($_POST['admin']!='')?$_POST['admin']:'';
   // $pic='pics/default.PNG';
    if(empty($Name))
    {
    header('Refresh:0;url=user.php');
    die("姓名不能为空");
    }
    else
    {
        $con=connect();
        $sql = "insert into user (username,password,isadmin) values ('{$Name}',MD5(''),$admin)";
        query($sql,$con);
        if($admin==0)
        {$sql = "select max(id) from user";
        $res=query($sql,$con);
        
        $a=mysqli_fetch_row($res);
        $id=$a[0];
        $sql = "insert into stuff (Name,gender,age,id) values ('{$Name}','{$gender}','{$age}','{$id}')";
        query($sql,$con);}
    echo "<script>
        location.href='user.php';
</script>";
    
    }
    
    
?>